import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 徐海涛
 * Date: 2021-12-12
 * Time: 18:21
 * //字符与字符串的相互转换
 *
 */
public class Test {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();//相当于一个拼接
        sb.append("asadasdsa");
        sb.append("12321321");
        System.out.println(sb);
        String str = "123";
        str += "avc";
        System.out.println(str);
    }
    public static void main12(String[] args) {
        String str = "abcdefg";
        String s = str.toUpperCase(Locale.ROOT);//转变为大写和小写
        System.out.println(s);
    }
    public static void main11(String[] args) {
        String str = "   avc   acx";
        String tirm = str.trim();//去除前后的空格
        System.out.println(tirm);
    }
    public static void main10(String[] args) {
        String str = "avcdefgh";
        String sub =str.substring(2,4);//左闭右开！
        System.out.println(sub);
    }
    public static void main9(String[] args) {
        String str = "name=zhangsan&age=18";
        String[] strings = str.split("&");
        for (String s :strings) {
            System.out.println(s);
        }
    }
    public static void main8(String[] args) {
        String str = "abcabcabc";//字符串的替换
        String ret = str.replace('a','g');
        System.out.println(ret);
    }

    public static void main7(String[] args) {
        //字符串的查找
        String str = "abcabcbc";
        String tmp = "abc";
        boolean flg = str.contains(tmp);//如果想要找个东西接tmp，注意返回值类型
        System.out.println(str.contains(tmp));
        int index = str.indexOf(2);
        System.out.println(index);//下标开始
    }
    //字符创建的操作
    public static void main6(String[] args) {
        String str1 = "abc";
        String str2 = "Abc";
        System.out.println(str1.equals(str2));
        //比较时如果想要忽略大小写
        System.out.println("==============");
        System.out.println(str1.equalsIgnoreCase(str2));//这里使用equalsIgnorecase
    }
    public static void main5(String[] args) {
        String str = "abcd";//将字符串转化为字节
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));
    }
    public static void main4(String[] args) {
        byte[] bytes = {97,98,99,100};//将字节转换为字符串和数一样
        String str = new String(bytes);
        System.out.println(str);
    }
    public static void main3(String[] args) {//获取某某一个字符
        String str = "hello";
        str.charAt(2);//获取某个下标的字符
        char ch = str.charAt(2);
        System.out.println(ch);
    }
    public static void main2(String[] args) {
        char[] val = {'a','b','c','d','e'};//一部分转换为字符串
        String str = new String(val,1,3); //offset偏移
        System.out.println(str);
    }
    public static void main1(String[] args) {//数组转换为字符串
        char[] val = {'1','2','3'};//char[]字符数组
        String str = new String(val);
        System.out.println(str);
    }
}
